const formatTime = date => {
  const year = date.getFullYear()
  const month = date.getMonth() + 1
  const day = date.getDate()
  const hour = date.getHours()
  const minute = date.getMinutes()
  const second = date.getSeconds()

  return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':')
}

const getDate = function() {
  let date = new Date(),
    year = date.getFullYear(),
    month = date.getMonth() + 1,
    day = date.getDate()
  
  return [year, month, day].map(formatNumber).join('-');
}

const getTime = function() {
  let date = new Date(),
    hour = date.getHours(),
    minute = date.getMinutes(),
    second = date.getSeconds();
  return [hour, minute, second].map(formatNumber).join(':');
}

const getDatetime = function(timestamp) {
  let date = new Date(timestamp);
  const year = date.getFullYear()
  const month = date.getMonth() + 1
  const day = date.getDate()
  const hour = date.getHours()
  const minute = date.getMinutes()
  const second = date.getSeconds()
  let res = [year, month, day].map(formatNumber).join('-') + ' ' + [hour, minute, second].map(formatNumber).join(':')
  return res;
}

const formatNumber = n => {
  n = n.toString()
  return n[1] ? n : '0' + n
}

const country = [
  { "name": "Andorra", "code": "AD", "area": "376" },
  { "name": "United Arab Emirates", "code": "AE", "area": "971" },
  { "name": "Afghanistan", "code": "AF", "area": "93" },
  { "name": "Antigua and Barbuda", "code": "AG", "area": "1268" },
  { "name": "Anguilla", "code": "AI", "area": "1254" },
  { "name": "Albania", "code": "AL", "area": "335" },
  { "name": "Armenia", "code": "AM", "area": "374" },
  { "name": "Angola", "code": "AO", "area": "0244" },
  { "name": "Argentina", "code": "AR", "area": "54" },
  { "name": "American Samoa", "code": "AS", "area": "684" },
  { "name": "Austria", "code": "AT", "area": "43" },
  { "name": "Australia", "code": "AU", "area": "61", "reg": /^(\+?61|0)4\d{8}$/ },
  { "name": "Azerbaijan", "code": "AZ", "area": "994" },
  { "name": "Barbados", "code": "BB", "area": "1246" },
  { "name": "Bangladesh", "code": "BD", "area": "880" },
  { "name": "Belgium", "code": "BE", "area": "32", "reg": /^(\+?32|0)4?\d{8}$/ },
  { "name": "Burkina Faso", "code": "BF", "area": "226" },
  { "name": "Bulgaria", "code": "BG", "area": "359" },
  { "name": "Bahrain", "code": "BH", "area": "973" },
  { "name": "Burundi", "code": "BI", "area": "257" },
  { "name": "Benin", "code": "BJ", "area": "229" },
  { "name": "Bermuda", "code": "BM", "area": "1441" },
  { "name": "Brunei Darussalam", "code": "BN", "area": "673" },
  { "name": "Bolivia (Plurinational State of)", "code": "BO", "area": "591" },
  { "name": "Brazil", "code": "BR", "area": "55", "reg": /^(\+?55|0)\-?[1-9]{2}\-?[2-9]{1}\d{3,4}\-?\d{4}$/ },
  { "name": "Bahamas", "code": "BS", "area": "1242" },
  { "name": "Botswana", "code": "BW", "area": "267" },
  { "name": "Belarus", "code": "BY", "area": "375" },
  { "name": "Belize", "code": "BZ", "area": "501" },
  { "name": "Canada", "code": "CA", "area": "1" },
  { "name": "Congo (Democratic Republic of the)", "code": "CD", "area": "242" },
  { "name": "Central African Republic", "code": "CF", "area": "236" },
  { "name": "Congo", "code": "CG", "area": "242" },
  { "name": "Switzerland", "code": "CH", "area": "41" },
  { "name": "Côte d'Ivoire", "code": "CI", "area": "225" },
  { "name": "Cook Islands", "code": "CK", "area": "682" },
  { "name": "Chile", "code": "CL", "area": "56" },
  { "name": "Cameroon", "code": "CM", "area": "237" },
  { "name": "China", "code": "CN", "area": "86", "reg": /^(\+?0?86\-?)?1[345789]\d{9}$/ },
  { "name": "Colombia", "code": "CO", "area": "57" },
  { "name": "Costa Rica", "code": "CR", "area": "506" },
  { "name": "Cuba", "code": "CU", "area": "53" },
  { "name": "Cyprus", "code": "CY", "area": "357" },
  { "name": "Czech Republic", "code": "CZ", "area": "420", "reg": /^(\+?420)? ?[1-9][0-9]{2} ?[0-9]{3} ?[0-9]{3}$/ },
  { "name": "Germany", "code": "DE", "area": "49", "reg": /^(\+?49[ \.\-])?([\(]{1}[0-9]{1,6}[\)])?([0-9 \.\-\/]{3,20})((x|ext|extension)[ ]?[0-9]{1,4})?$/ },
  { "name": "Djibouti", "code": "DJ", "area": "253" },
  { "name": "Denmark", "code": "DK", "area": "45", "reg": /^(\+?45)?(\d{8})$/ },
  { "name": "Dominican Republic", "code": "DO", "area": "1890" },
  { "name": "Algeria", "code": "DZ", "area": "213", "reg": /^(\+?213|0)(5|6|7)\d{8}$/ },
  { "name": "Ecuador", "code": "EC", "area": "593" },
  { "name": "Estonia", "code": "EE", "area": "372" },
  { "name": "Egypt", "code": "EG", "area": "20" },
  { "name": "Spain", "code": "ES", "area": "34", "reg": /^(\+?34)?(6\d{1}|7[1234])\d{7}$/ },
  { "name": "Ethiopia", "code": "ET", "area": "251" },
  { "name": "Finland", "code": "FI", "area": "358", "reg": /^(\+?358|0)\s?(4(0|1|2|4|5)?|50)\s?(\d\s?){4,8}\d$/ },
  { "name": "Fiji", "code": "FJ", "area": "679" },
  { "name": "France", "code": "FR", "area": "33", "reg": /^(\+?33|0)[67]\d{8}$/ },
  { "name": "Gabon", "code": "GA", "area": "241" },
  { "name": "United Kingdom", "code": "GB", "area": "44", "reg": /^(\+?44|0)7\d{9}$/ },
  { "name": "Grenada", "code": "GD", "area": "1809" },
  { "name": "Georgia", "code": "GE", "area": "995" },
  { "name": "French Guiana", "code": "GF", "area": "594" },
  { "name": "Ghana", "code": "GH", "area": "233" },
  { "name": "Gibraltar", "code": "GI", "area": "350" },
  { "name": "Gambia", "code": "GM", "area": "220" },
  { "name": "Guinea", "code": "GN", "area": "224" },
  { "name": "Equatorial Guinea", "code": "GQ", "area": "224" },
  { "name": "Greece", "code": "GR", "area": "30", "reg": /^(\+?30)?(69\d{8})$/ },
  { "name": "South Georgia and the South Sandwich Islands", "code": "GS", "area": "995" },
  { "name": "Guatemala", "code": "GT", "area": "502" },
  { "name": "Guam", "code": "GU", "area": "1671" },
  { "name": "Guinea-Bissau", "code": "GW", "area": "224" },
  { "name": "Guyana", "code": "GY", "area": "592" },
  { "name": "Hong Kong", "code": "HK", "area": "852", "reg": /^(\+?852\-?)?[569]\d{3}\-?\d{4}$/ },
  { "name": "Honduras", "code": "HN", "area": "504" },
  { "name": "Croatia", "code": "HR", "area": "381" },
  { "name": "Haiti", "code": "HT", "area": "509" },
  { "name": "Hungary", "code": "HU", "area": "36", "reg": /^(\+?36)(20|30|70)\d{7}$/ },
  { "name": "Indonesia", "code": "ID", "area": "62" },
  { "name": "Ireland", "code": "IE", "area": "353" },
  { "name": "Israel", "code": "IL", "area": "972", "reg": /^(\+972|0)([23489]|5[0248]|77)[1-9]\d{6}/ },
  { "name": "India", "code": "IN", "area": "91", "reg": /^(\+?91|0)?[789]\d{9}$/ },
  { "name": "Iraq", "code": "IQ", "area": "964" },
  { "name": "Iran (Islamic Republic of)", "code": "IR", "area": "98" },
  { "name": "Iceland", "code": "IS", "area": "354" },
  { "name": "Italy", "code": "IT", "area": "39", "reg": /^(\+?39)?\s?3\d{2} ?\d{6,7}$/ },
  { "name": "Jamaica", "code": "JM", "area": "1876" },
  { "name": "Jordan", "code": "JO", "area": "962" },
  { "name": "Japan", "code": "JP", "area": "81", "reg": /^(\+?81|0)\d{1,4}[ \-]?\d{1,4}[ \-]?\d{4}$/ },
  { "name": "Kenya", "code": "KE", "area": "254" },
  { "name": "Kyrgyzstan", "code": "KG", "area": "331" },
  { "name": "Cambodia", "code": "KH", "area": "855" },
  { "name": "Korea (Democratic People's Republic of)", "code": "KP", "area": "850" },
  { "name": "Korea (Republic of)", "code": "KR", "area": "82" },
  { "name": "Kuwait", "code": "KW", "area": "965" },
  { "name": "Cayman Islands", "code": "KY", "area": "1345" },
  { "name": "Kazakhstan", "code": "KZ", "area": "7" },
  { "name": "Lao People's Democratic Republic", "code": "LA", "area": "856" },
  { "name": "Lebanon", "code": "LB", "area": "961" },
  { "name": "Saint Lucia", "code": "LC", "area": "1785" },
  { "name": "Liechtenstein", "code": "LI", "area": "423" },
  { "name": "Sri Lanka", "code": "LK", "area": "94" },
  { "name": "Liberia", "code": "LR", "area": "231" },
  { "name": "Lesotho", "code": "LS", "area": "266" },
  { "name": "Lithuania", "code": "LT", "area": "370" },
  { "name": "Luxembourg", "code": "LU", "area": "352" },
  { "name": "Latvia", "code": "LV", "area": "371" },
  { "name": "Libya", "code": "LY", "area": "218" },
  { "name": "Morocco", "code": "MA", "area": "212" },
  { "name": "Monaco", "code": "MC", "area": "377" },
  { "name": "Moldova (Republic of)", "code": "MD", "area": "373" },
  { "name": "Montenegro", "code": "ME", "area": "382" },
  { "name": "Saint Martin (French part)", "code": "MF", "area": "00" },
  { "name": "Madagascar", "code": "MG", "area": "261" },
  { "name": "Marshall Islands", "code": "MH", "area": "692" },
  { "name": "Macedonia (the former Yugoslav Republic of)", "code": "MK", "area": "389" },
  { "name": "Mali", "code": "ML", "area": "223" },
  { "name": "Myanmar", "code": "MM", "area": "95" },
  { "name": "Mongolia", "code": "MN", "area": "976" },
  { "name": "Macao", "code": "MO", "area": "853" },
  { "name": "Northern Mariana Islands", "code": "MP", "area": "1670" },
  { "name": "Martinique", "code": "MQ", "area": "596" },
  { "name": "Mauritania", "code": "MR", "area": "222" },
  { "name": "Montserrat", "code": "MS", "area": "1664" },
  { "name": "Malta", "code": "MT", "area": "356" },
  { "name": "Mauritius", "code": "MU", "area": "230" },
  { "name": "Maldives", "code": "MV", "area": "960" },
  { "name": "Malawi", "code": "MW", "area": "265" },
  { "name": "Mexico", "code": "MX", "area": "52" },
  { "name": "Malaysia", "code": "MY", "area": "60", "reg": /^(\+?6?01){1}(([145]{1}(\-|\s)?\d{7,8})|([236789]{1}(\s|\-)?\d{7}))$/ },
  { "name": "Mozambique", "code": "MZ", "area": "258" },
  { "name": "Namibia", "code": "NA", "area": "264" },
  { "name": "New Caledonia", "code": "NC", "area": "687" },
  { "name": "Niger", "code": "NE", "area": "227" },
  { "name": "Norfolk Island", "code": "NF", "area": "672" },
  { "name": "Nigeria", "code": "NG", "area": "234" },
  { "name": "Nicaragua", "code": "NI", "area": "505" },
  { "name": "Netherlands", "code": "NL", "area": "31" },
  { "name": "Norway", "code": "NO", "area": "47", "reg": /^(\+?47)?[49]\d{7}$/ },
  { "name": "Nepal", "code": "NP", "area": "977" },
  { "name": "Nauru", "code": "NR", "area": "674" },
  { "name": "Niue", "code": "NU", "area": "683" },
  { "name": "New Zealand", "code": "NZ", "area": "64", "reg": /^(\+?64|0)2\d{7,9}$/ },
  { "name": "Oman", "code": "OM", "area": "968" },
  { "name": "Panama", "code": "PA", "area": "507" },
  { "name": "Peru", "code": "PE", "area": "51" },
  { "name": "French Polynesia", "code": "PF", "area": "689" },
  { "name": "Papua New Guinea", "code": "PG", "area": "675" },
  { "name": "Philippines", "code": "PH", "area": "63" },
  { "name": "Pakistan", "code": "PK", "area": "92" },
  { "name": "Poland", "code": "PL", "area": "48", "reg": /^(\+?48)? ?[5-8]\d ?\d{3} ?\d{2} ?\d{2}$/ },
  { "name": "Saint Pierre and Miquelon", "code": "PM", "area": "508" },
  { "name": "Pitcairn", "code": "PN", "area": "64" },
  { "name": "Puerto Rico", "code": "PR", "area": "1787" },
  { "name": "Palestine, State of", "code": "PS", "area": "970" },
  { "name": "Portugal", "code": "PT", "area": "351", "reg": /^(\+?351)?9[1236]\d{7}$/ },
  { "name": "Palau", "code": "PW", "area": "680" },
  { "name": "Paraguay", "code": "PY", "area": "595" },
  { "name": "Qatar", "code": "QA", "area": "974" },
  { "name": "Romania", "code": "RO", "area": "40" },
  { "name": "Serbia", "code": "RS", "area": "381" },
  { "name": "Russian Federation", "code": "RU", "area": "7", "reg": /^(\+?7|8)?9\d{9}$/ },
  { "name": "Rwanda", "code": "RW", "area": "250" },
  { "name": "Saudi Arabia", "code": "SA", "area": "966", "reg": /^(!?(\+?966)|0)?5\d{8}$/ },
  { "name": "Solomon Islands", "code": "SB", "area": "677" },
  { "name": "Seychelles", "code": "SC", "area": "248" },
  { "name": "Sudan", "code": "SD", "area": "249" },
  { "name": "Sweden", "code": "SE", "area": "46" },
  { "name": "Singapore", "code": "SG", "area": "65" },
  { "name": "Slovenia", "code": "SI", "area": "386" },
  { "name": "Svalbard and Jan Mayen", "code": "SJ", "area": "744" },
  { "name": "Slovakia", "code": "SK", "area": "421" },
  { "name": "Sierra Leone", "code": "SL", "area": "232" },
  { "name": "San Marino", "code": "SM", "area": "378" },
  { "name": "Senegal", "code": "SN", "area": "221" },
  { "name": "Somalia", "code": "SO", "area": "252" },
  { "name": "Suriname", "code": "SR", "area": "597" },
  { "name": "South Sudan", "code": "SS", "area": "211" },
  { "name": "Sao Tome and Principe", "code": "ST", "area": "239" },
  { "name": "El Salvador", "code": "SV", "area": "503" },
  { "name": "Sint Maarten (Dutch part)", "code": "SX", "area": "599" },
  { "name": "Syrian Arab Republic", "code": "SY", "area": "963", "reg": /^(!?(\+?963)|0)?9\d{8}$/ },
  { "name": "Swaziland", "code": "SZ", "area": "268" },
  { "name": "Turks and Caicos Islands", "code": "TC", "area": "1649" },
  { "name": "Chad", "code": "TD", "area": "235" },
  { "name": "Togo", "code": "TG", "area": "228" },
  { "name": "Thailand", "code": "TH", "area": "66" },
  { "name": "Tajikistan", "code": "TJ", "area": "992" },
  { "name": "Tokelau", "code": "TK", "area": "690" },
  { "name": "Timor-Leste", "code": "TL", "area": "670" },
  { "name": "Turkmenistan", "code": "TM", "area": "993" },
  { "name": "Tunisia", "code": "TN", "area": "216" },
  { "name": "Tonga", "code": "TO", "area": "676" },
  { "name": "Turkey", "code": "TR", "area": "90", "reg": /^(\+?90|0)?5\d{9}$/ },
  { "name": "Trinidad and Tobago", "code": "TT", "area": "1868" },
  { "name": "Tuvalu", "code": "TV", "area": "688" },
  { "name": "Taiwan, Province of China", "code": "TW", "area": "886", "reg": /^(\+?886\-?|0)?9\d{8}$/ },
  { "name": "Tanzania, United Republic of", "code": "TZ", "area": "255" },
  { "name": "Ukraine", "code": "UA", "area": "380" },
  { "name": "Uganda", "code": "UG", "area": "256" },
  { "name": "United States", "code": "US", "area": "1", "reg": /^(\+?1)?[2-9]\d{2}[2-9](?!11)\d{6}$/ },
  { "name": "Uruguay", "code": "UY", "area": "598" },
  { "name": "Uzbekistan", "code": "UZ", "area": "998" },
  { "name": "Saint Vincent and the Grenadines", "code": "VC", "area": "1784" },
  { "name": "Venezuela (Bolivarian Republic of)", "code": "VE", "area": "58" },
  { "name": "Virgin Islands (British)", "code": "VG", "area": "1284" },
  { "name": "Virgin Islands (U.S.)", "code": "VI", "area": "1340" },
  { "name": "Vietnam", "code": "VN", "area": "84", "reg": /^(\+?84|0)?((1(2([0-9])|6([2-9])|88|99))|(9((?!5)[0-9])))([0-9]{7})$/ },
  { "name": "Vanuatu", "code": "VU", "area": "678" },
  { "name": "Wallis and Futuna", "code": "WF", "area": "681" },
  { "name": "Samoa", "code": "WS", "area": "685" },
  { "name": "Yemen", "code": "YE", "area": "967" },
  { "name": "Mayotte", "code": "YT", "area": "262" },
  { "name": "South Africa", "code": "ZA", "area": "27", "reg": /^(\+?27|0)\d{9}$/ },
  { "name": "Zambia", "code": "ZM", "area": "260", "reg": /^(\+?26)?09[567]\d{7}$/ },
  { "name": "Zimbabwe", "code": "ZW", "area": "263" }
]

module.exports = {
  formatTime: formatTime,
  getDate: getDate,
  getTime: getTime,
  getDatetime: getDatetime,
  country: country
}
